/*
    The MIT License

    Copyright (c) 2010 IFMO/GameDev Studio

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/

#pragma once

/*-----------------------------------------------------------------------------
	File system :
-----------------------------------------------------------------------------*/

class	IFileSystem;
class	IFile;
class	IFSSearch;
typedef HardRef<IFileSystem>	IHrFileSystem;
typedef HardRef<IFile>			IHrFile;
typedef HardRef<IFSSearch>		IHrFSSearch;


enum FileSeekMode {
		FS_SEEK_BEGIN,
		FS_SEEK_END,
		FS_SEEK_CURRENT,
	};
	
enum FileOpenMode {
		FS_OPEN_READ,
		FS_OPEN_WRITE,
		FS_OPEN_APPEND,
	};


class IFile : public ICoreObject { 
	public:								
		virtual const char		*name			( void ) const = 0;
		virtual uint			size			( void ) const = 0;
		virtual FileOpenMode	Mode			( void ) const = 0;
											
		virtual uint			read			( void *buffer, uint size ) = 0;
		virtual uint			write			( const void *buffer, uint size ) = 0;
		virtual uint			seek			( int dist, FileSeekMode origin ) = 0;
		
		virtual void			flush			( void ) = 0;
		virtual void			printf			( const char *frmt, ... ) = 0;
		
		virtual IPxBlob			binaryBlob		( void ) = 0;
		virtual IPxBlob			stringBlob		( void ) = 0;
	};
	
	
class IFSSearch : public ICoreObject { 
	public:
		virtual	uint			getItemNum		( void ) const = 0;
		virtual const char	*	getItemName		( uint n ) const = 0;
	};


class IFileSystem { 
	public:
		virtual					~IFileSystem	( void ) {};
		
		virtual void			UpdatePackInfo	( void ) = 0;

		virtual	void			makeDirectory	( const char *path ) = 0;
		virtual void			removeDirectory	( const char *path ) = 0;
		virtual void			changeDirectory	( const char *path ) = 0;
		virtual void			makePath		( const char *path ) = 0;
		virtual const char	*	getDirectory		( void ) = 0;
		
		virtual	EString			startupDir		( void ) = 0;
		virtual EString			resolvePath		( const EString path ) = 0;

		virtual bool			isFileExist		( const char *path ) = 0;
		virtual void			deleteFile		( const char *path ) = 0;
		virtual const char	*	genUniqueName	( const char *path, const char *part, const char *ext ) = 0;
		
		virtual IHrFile			openFile		( const char *name, FileOpenMode mode ) = 0;
		
		virtual	IHrFSSearch		search			( const char *dir, const char *mask, bool ignore_archives=false ) = 0;
	};
	
